package com.wk.unreal.yyzxserver.service.impl;

import com.wk.unreal.yyzxserver.dto.Result;
import com.wk.unreal.yyzxserver.entity.Menu;
import com.wk.unreal.yyzxserver.mapper.MenuMapper;
import com.wk.unreal.yyzxserver.service.MenuService;
import com.wk.unreal.yyzxserver.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public Result menus() {
        // 获取线程里面存入的数据
        Map<String, Object> claims = ThreadLocalUtil.get();
        // 获取的一级菜单
        List<Menu> menus = menuMapper.menus((Integer) claims.get("roleId"));
        for (Menu menu : menus) {
            // 获取每一个一级菜单的所有二级菜单
            menu.setChildren(menuMapper.childrenMenu(menu.getId()));
        }

        return Result.success().data(menus);
    }
}
